{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import sys\n",
    "from sklearn.preprocessing import normalize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "xy = np.loadtxt('C:\\\\Users\\\\SANHA\\\\Desktop\\\\new_data.csv', delimiter=',', dtype=np.float32)\n",
    "x_data=xy[:,0:-1]\n",
    "x_data = normalize(x_data, axis=0, norm='max')\n",
    "xy[:,0:-1]=x_data\n",
    "y_data=xy[:,[-1]]\n",
    "m_data=xy[:499,:]\n",
    "r_data=xy[:10000,:]\n",
    "g_data=xy[:0,:]\n",
    "F_data=xy[:,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Model Inputs\n",
    "def model_inputs(real_dim, noise_dim):\n",
    "    inputs_real_ = tf.placeholder(tf.float32, shape=[None, real_dim], name='inputs_real')\n",
    "    inputs_z_ = tf.placeholder(tf.float32, shape=[None, noise_dim], name='inputs_z')\n",
    "    \n",
    "    return inputs_real_, inputs_z_\n",
    "\n",
    "def leaky_relu(x, alpha):\n",
    "    return tf.maximum(alpha * x, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Generator Network\n",
    "def model_generator(z_input, out_dim, n_units=128, reuse=False, alpha=0.01):\n",
    "    # used to reuse variables, name scope\n",
    "    with tf.variable_scope('generator', reuse=reuse):\n",
    "        hidden_layer = tf.layers.dense(z_input, n_units, activation=None)\n",
    "        hidden_layer = leaky_relu(hidden_layer, alpha)\n",
    "        \n",
    "        logits = tf.layers.dense(hidden_layer, out_dim, activation=None)\n",
    "        outputs = tf.nn.sigmoid(logits)\n",
    "        \n",
    "        return outputs, logits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Discriminator Network\n",
    "def model_discriminator(input, n_units=128, reuse=False, alpha=0.1):\n",
    "    with tf.variable_scope('discriminator', reuse=reuse):\n",
    "        hidden_layer = tf.layers.dense(input, n_units, activation=tf.nn.relu)\n",
    "        #hidden_layer = leaky_relu(hidden_layer, alpha)\n",
    "        \n",
    "        logits = tf.layers.dense(hidden_layer, 1, activation=None)\n",
    "        outputs = tf.nn.sigmoid(logits)\n",
    "        \n",
    "        return outputs, logits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#parameter\n",
    "input_size = 42\n",
    "z_dim = 21\n",
    "g_hidden_size = 128\n",
    "d_hidden_size = 128\n",
    "alpha = 0.1\n",
    "smooth = 0.1\n",
    "learning_rate = 0.001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "tf.reset_default_graph()  # If we don't have this, as we call this block over and over, the graph gets bigger and bigger\n",
    "\n",
    "graph = tf.Graph()\n",
    "with graph.as_default():\n",
    "    inputs_real, inputs_z = model_inputs(input_size, z_dim)\n",
    "    \n",
    "    g_outputs, g_logits = model_generator(inputs_z, input_size, n_units=g_hidden_size, reuse=False, alpha=alpha)\n",
    "    \n",
    "    d_outputs_real, d_logits_real = model_discriminator(inputs_real, n_units=d_hidden_size, reuse=False, alpha=alpha)\n",
    "    d_outputs_fake, d_logits_fake = model_discriminator(g_outputs, n_units=d_hidden_size, reuse=True, alpha=alpha)\n",
    "    \n",
    "    d_loss_real = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=d_logits_real, labels=tf.ones_like(d_logits_real) * (1-smooth)))\n",
    "    d_loss_fake = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=d_logits_fake, labels=tf.zeros_like(d_logits_fake)))\n",
    "    \n",
    "    d_loss = d_loss_real + d_loss_fake\n",
    "    g_loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=d_logits_fake, labels=tf.ones_like(d_logits_fake)))\n",
    "    \n",
    "    t_vars = tf.trainable_variables()\n",
    "    g_vars = [variable for variable in t_vars if 'generator' in variable.name]\n",
    "    d_vars = [variable for variable in t_vars if 'discriminator' in variable.name]\n",
    "    \n",
    "    # Affected Variables with var_list\n",
    "    d_optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(d_loss, var_list=d_vars)\n",
    "    g_optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(g_loss, var_list=g_vars)\n",
    "    \n",
    "    # Saving variables with var_list\n",
    "    saver = tf.train.Saver(var_list=g_vars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 / 100000: 1.422688, 0.763870Generating Complete. normal=1, abnormal=0\n"
     ]
    }
   ],
   "source": [
    "samples=[]\n",
    "normal=0\n",
    "abnormal=0\n",
    "\n",
    "with tf.Session(graph=graph) as sess:\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    f = open('C:\\\\Users\\\\SANHA\\\\Desktop\\\\gen_sample3333.txt', 'a+')\n",
    "    for step in range(1):\n",
    "        \n",
    "        \n",
    "        batch_images = F_data[step].reshape([1, 42])\n",
    "        batch_z = np.random.uniform(-1, 1, size=[1, z_dim])\n",
    "        \n",
    "        _ = sess.run(d_optimizer, feed_dict={inputs_real : batch_images, inputs_z : batch_z})\n",
    "        _ = sess.run(g_optimizer, feed_dict={inputs_z : batch_z})\n",
    "        loss_d, loss_g = sess.run([d_loss, g_loss], feed_dict={inputs_real : batch_images, inputs_z : batch_z})\n",
    "        #if step%1000==0:\n",
    "        #    print('step {} / {} Complete. D_Loss : {:0.3f}, G_Loss : {:0.3f}'.format(step+1, 100000, loss_d, loss_g))\n",
    "        sys.stdout.write(\"\\r%d / %d: %f, %f\" % (step, 100000, loss_d, loss_g))\n",
    "        sys.stdout.flush()\n",
    "        sample_z = np.random.uniform(-1, 1, size=[1, z_dim])  # 16 Samples each epoch\n",
    "        gen_samples, _ = sess.run(model_generator(inputs_z, input_size, reuse=True), feed_dict={inputs_z : sample_z})\n",
    "        \n",
    "        temp=gen_samples[0,41]\n",
    "        #print(temp)\n",
    "        if temp>=0.5:\n",
    "            gen_samples[0,41]=1\n",
    "            abnormal+=1\n",
    "        else :\n",
    "            gen_samples[0,41]=0\n",
    "            normal+=1\n",
    "        #print(temp,gen_samples[0,41])\n",
    "        #write for text to csv\n",
    "        f.write(\"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \\n\" %(gen_samples[0,0],gen_samples[0,1],gen_samples[0,2],gen_samples[0,3],gen_samples[0,4],gen_samples[0,5],gen_samples[0,6],gen_samples[0,7],gen_samples[0,8],gen_samples[0,9],gen_samples[0,10],gen_samples[0,11],gen_samples[0,12],gen_samples[0,13],gen_samples[0,14],gen_samples[0,15],gen_samples[0,16],gen_samples[0,17],gen_samples[0,18],gen_samples[0,19],gen_samples[0,20],gen_samples[0,21],gen_samples[0,22],gen_samples[0,23],gen_samples[0,24],gen_samples[0,25],gen_samples[0,26],gen_samples[0,27],gen_samples[0,28],gen_samples[0,29],gen_samples[0,30],gen_samples[0,31],gen_samples[0,32],gen_samples[0,33],gen_samples[0,34],gen_samples[0,35],gen_samples[0,36],gen_samples[0,37],gen_samples[0,38],gen_samples[0,39],gen_samples[0,40],gen_samples[0,41]))\n",
    "       \n",
    "        \n",
    "    print('Generating Complete. normal={}, abnormal={}'.format(normal,abnormal))\n",
    "    f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "finished\n"
     ]
    }
   ],
   "source": [
    "xy2 = np.genfromtxt('C:\\\\Users\\\\SANHA\\\\Desktop\\\\mix_data_40000.csv', delimiter=',', dtype=np.float32)\n",
    "xy3 = np.loadtxt('C:\\\\Users\\\\SANHA\\\\Desktop\\\\gen_data.csv', delimiter=',', dtype=np.float32)\n",
    "xy4 = np.loadtxt('C:\\\\Users\\\\SANHA\\\\Desktop\\\\false_data.csv', delimiter=',', dtype=np.float32)\n",
    "#gen data 20000\n",
    "gx_data=xy3[:,0:-1]\n",
    "gy_data=xy3[:,[-1]]\n",
    "gF_data=xy3[:,:]\n",
    "\n",
    "#gen 20000+real 20000\n",
    "mx_data=xy2[:39999,0:-1]\n",
    "my_data=xy2[:39999,[-1]]\n",
    "mF_data=xy2[:39999,:]\n",
    "\n",
    "#real data 40000\n",
    "tx_data=r_data[:40000,0:-1]\n",
    "ty_data=r_data[:40000,[-1]]\n",
    "\n",
    "#false data\n",
    "F_data=xy4[:,:]\n",
    "Fx_data=xy4[:,0:-1]\n",
    "Fy_data=xy4[:,[-1]]\n",
    "print(\"finished\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "step:     0\tLoss: 0.669\tAcc: 66.50%\n",
      "step:    10\tLoss: 0.832\tAcc: 58.92%\n",
      "step:    20\tLoss: 1.035\tAcc: 60.39%\n",
      "step:    30\tLoss: 1.265\tAcc: 59.17%\n",
      "step:    40\tLoss: 1.432\tAcc: 58.56%\n",
      "step:    50\tLoss: 1.501\tAcc: 57.58%\n",
      "step:    60\tLoss: 1.508\tAcc: 57.46%\n",
      "step:    70\tLoss: 1.517\tAcc: 57.70%\n",
      "step:    80\tLoss: 1.567\tAcc: 58.19%\n",
      "step:    90\tLoss: 1.636\tAcc: 59.90%\n",
      "step:   100\tLoss: 1.689\tAcc: 61.98%\n",
      "step:   110\tLoss: 1.732\tAcc: 63.08%\n",
      "step:   120\tLoss: 1.771\tAcc: 64.18%\n",
      "step:   130\tLoss: 1.835\tAcc: 64.30%\n",
      "step:   140\tLoss: 1.864\tAcc: 64.91%\n",
      "step:   150\tLoss: 1.913\tAcc: 65.89%\n",
      "step:   160\tLoss: 1.944\tAcc: 66.38%\n",
      "step:   170\tLoss: 1.972\tAcc: 66.75%\n",
      "step:   180\tLoss: 1.999\tAcc: 67.97%\n",
      "step:   190\tLoss: 2.016\tAcc: 68.46%\n",
      "step:   200\tLoss: 2.032\tAcc: 68.95%\n",
      "step:   210\tLoss: 2.056\tAcc: 69.80%\n",
      "step:   220\tLoss: 2.078\tAcc: 70.17%\n",
      "step:   230\tLoss: 2.089\tAcc: 71.15%\n",
      "step:   240\tLoss: 2.114\tAcc: 71.15%\n",
      "step:   250\tLoss: 2.109\tAcc: 71.52%\n",
      "step:   260\tLoss: 2.116\tAcc: 71.88%\n",
      "step:   270\tLoss: 2.119\tAcc: 72.00%\n",
      "step:   280\tLoss: 2.119\tAcc: 72.25%\n",
      "step:   290\tLoss: 2.125\tAcc: 72.86%\n",
      "step:   300\tLoss: 2.135\tAcc: 72.98%\n",
      "step:   310\tLoss: 2.138\tAcc: 72.86%\n",
      "step:   320\tLoss: 2.146\tAcc: 73.11%\n",
      "step:   330\tLoss: 2.160\tAcc: 73.11%\n",
      "step:   340\tLoss: 2.172\tAcc: 73.72%\n",
      "step:   350\tLoss: 2.177\tAcc: 73.72%\n",
      "step:   360\tLoss: 2.173\tAcc: 73.72%\n",
      "step:   370\tLoss: 2.187\tAcc: 73.84%\n",
      "step:   380\tLoss: 2.193\tAcc: 74.08%\n",
      "step:   390\tLoss: 2.199\tAcc: 74.21%\n",
      "step:   400\tLoss: 2.199\tAcc: 74.33%\n",
      "step:   410\tLoss: 2.209\tAcc: 74.45%\n",
      "step:   420\tLoss: 2.222\tAcc: 74.21%\n",
      "step:   430\tLoss: 2.210\tAcc: 74.57%\n",
      "step:   440\tLoss: 2.216\tAcc: 74.45%\n",
      "step:   450\tLoss: 2.221\tAcc: 74.21%\n",
      "step:   460\tLoss: 2.222\tAcc: 74.21%\n",
      "step:   470\tLoss: 2.224\tAcc: 74.45%\n",
      "step:   480\tLoss: 2.240\tAcc: 73.84%\n",
      "step:   490\tLoss: 2.231\tAcc: 74.21%\n",
      "step:   500\tLoss: 2.233\tAcc: 74.33%\n",
      "step:   510\tLoss: 2.232\tAcc: 74.33%\n",
      "step:   520\tLoss: 2.234\tAcc: 74.21%\n",
      "step:   530\tLoss: 2.235\tAcc: 74.08%\n",
      "step:   540\tLoss: 2.235\tAcc: 74.08%\n",
      "step:   550\tLoss: 2.235\tAcc: 73.84%\n",
      "step:   560\tLoss: 2.234\tAcc: 73.72%\n",
      "step:   570\tLoss: 2.230\tAcc: 73.84%\n",
      "step:   580\tLoss: 2.231\tAcc: 73.96%\n",
      "step:   590\tLoss: 2.228\tAcc: 73.96%\n",
      "step:   600\tLoss: 2.226\tAcc: 73.84%\n",
      "step:   610\tLoss: 2.225\tAcc: 73.84%\n",
      "step:   620\tLoss: 2.224\tAcc: 74.08%\n",
      "step:   630\tLoss: 2.223\tAcc: 74.21%\n",
      "step:   640\tLoss: 2.223\tAcc: 74.21%\n",
      "step:   650\tLoss: 2.223\tAcc: 74.21%\n",
      "step:   660\tLoss: 2.222\tAcc: 74.08%\n",
      "step:   670\tLoss: 2.221\tAcc: 74.08%\n",
      "step:   680\tLoss: 2.218\tAcc: 74.08%\n",
      "step:   690\tLoss: 2.213\tAcc: 74.21%\n",
      "step:   700\tLoss: 2.206\tAcc: 74.33%\n",
      "step:   710\tLoss: 2.199\tAcc: 74.33%\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-98-14fb84576533>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     34\u001b[0m     \u001b[0mf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'C:\\\\Users\\\\SANHA\\\\Desktop\\\\false_data.txt'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'a+'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     35\u001b[0m     \u001b[1;32mfor\u001b[0m \u001b[0mstep\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1000\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 36\u001b[1;33m         \u001b[0msess\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0moptimizer\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mfeed_dict\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mx_data\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mY\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0my_data\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     37\u001b[0m         \u001b[1;31m#print(\"training by gan sample\")\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     38\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mstep\u001b[0m \u001b[1;33m%\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m==\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36mrun\u001b[1;34m(self, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m    898\u001b[0m     \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    899\u001b[0m       result = self._run(None, fetches, feed_dict, options_ptr,\n\u001b[1;32m--> 900\u001b[1;33m                          run_metadata_ptr)\n\u001b[0m\u001b[0;32m    901\u001b[0m       \u001b[1;32mif\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    902\u001b[0m         \u001b[0mproto_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrun_metadata_ptr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_run\u001b[1;34m(self, handle, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m   1133\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mfinal_fetches\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mfinal_targets\u001b[0m \u001b[1;32mor\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mhandle\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mfeed_dict_tensor\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1134\u001b[0m       results = self._do_run(handle, final_targets, final_fetches,\n\u001b[1;32m-> 1135\u001b[1;33m                              feed_dict_tensor, options, run_metadata)\n\u001b[0m\u001b[0;32m   1136\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1137\u001b[0m       \u001b[0mresults\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_run\u001b[1;34m(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m   1314\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mhandle\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1315\u001b[0m       return self._do_call(_run_fn, feeds, fetches, targets, options,\n\u001b[1;32m-> 1316\u001b[1;33m                            run_metadata)\n\u001b[0m\u001b[0;32m   1317\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1318\u001b[0m       \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_do_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_prun_fn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhandle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeeds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetches\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_call\u001b[1;34m(self, fn, *args)\u001b[0m\n\u001b[0;32m   1320\u001b[0m   \u001b[1;32mdef\u001b[0m \u001b[0m_do_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1321\u001b[0m     \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1322\u001b[1;33m       \u001b[1;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1323\u001b[0m     \u001b[1;32mexcept\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mOpError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1324\u001b[0m       \u001b[0mmessage\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcompat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mas_text\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_run_fn\u001b[1;34m(feed_dict, fetch_list, target_list, options, run_metadata)\u001b[0m\n\u001b[0;32m   1305\u001b[0m       \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_extend_graph\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1306\u001b[0m       return self._call_tf_sessionrun(\n\u001b[1;32m-> 1307\u001b[1;33m           options, feed_dict, fetch_list, target_list, run_metadata)\n\u001b[0m\u001b[0;32m   1308\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1309\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_prun_fn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhandle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetch_list\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_call_tf_sessionrun\u001b[1;34m(self, options, feed_dict, fetch_list, target_list, run_metadata)\u001b[0m\n\u001b[0;32m   1407\u001b[0m       return tf_session.TF_SessionRun_wrapper(\n\u001b[0;32m   1408\u001b[0m           \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_session\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moptions\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetch_list\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtarget_list\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1409\u001b[1;33m           run_metadata)\n\u001b[0m\u001b[0;32m   1410\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1411\u001b[0m       \u001b[1;32mwith\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mraise_exception_on_not_ok_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mstatus\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "\n",
    "nb_classes=2\n",
    "\n",
    "X=tf.placeholder(tf.float32,[None,41])\n",
    "Y=tf.placeholder(tf.int32,[None,1])\n",
    "\n",
    "Y_one_hot=tf.one_hot(Y,nb_classes)\n",
    "Y_one_hot=tf.reshape(Y_one_hot,[-1,nb_classes])\n",
    "\n",
    "W1=tf.Variable(tf.random_normal([41,41]),name='weight1')\n",
    "b1=tf.Variable(tf.random_normal([41]),name='bias1')\n",
    "layer1=tf.sigmoid(tf.matmul(X,W1)+b1)\n",
    "\n",
    "W2=tf.Variable(tf.random_normal([41,41]),name='weight2')\n",
    "b2=tf.Variable(tf.random_normal([41]),name='bias2')\n",
    "layer2=tf.sigmoid(tf.matmul(layer1,W2)+b2)\n",
    "\n",
    "W3=tf.Variable(tf.random_normal([41,nb_classes]),name='weight3')\n",
    "b3=tf.Variable(tf.random_normal([nb_classes]),name='bias3')\n",
    "logits=tf.matmul(layer2,W3)+b3\n",
    "hypothesis=tf.nn.softmax(logits)\n",
    "\n",
    "cost_i=tf.nn.softmax_cross_entropy_with_logits(logits=logits,labels=Y_one_hot)\n",
    "\n",
    "cost=tf.reduce_mean(cost_i)\n",
    "optimizer=tf.train.AdamOptimizer(learning_rate=0.01).minimize(cost)\n",
    "\n",
    "prediction=tf.argmax(hypothesis,1) #가능성을 퍼센트로~~\n",
    "correct_prediction=tf.equal(prediction,tf.arg_max(Y_one_hot,1))\n",
    "accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    f = open('C:\\\\Users\\\\SANHA\\\\Desktop\\\\false_data.txt', 'a+')\n",
    "    for step in range(1000):\n",
    "        sess.run(optimizer,feed_dict={X:x_data,Y:y_data})\n",
    "        #print(\"training by gan sample\")\n",
    "        if step %10==0:\n",
    "            loss,acc=sess.run([cost,accuracy],feed_dict={X:Fx_data,Y:Fy_data})\n",
    "            print(\"step: {:5}\\tLoss: {:.3f}\\tAcc: {:.2%}\".format(step,loss,acc))\n",
    "  \n",
    "    tr=0\n",
    "    fa=0\n",
    "    total=0\n",
    "#m_data=np.append(m_data,gen_samples,axis=0)\n",
    "\n",
    "    pred = sess.run(prediction, feed_dict={X: x_data})\n",
    "    for p, y in zip(pred, y_data.flatten()):\n",
    "            if(p==int(y)):\n",
    "                tr=tr+1\n",
    "            else:\n",
    "                fa=fa+1\n",
    "                #print(gx_data)\n",
    "                f.write(\"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \\n\" %(gx_data[fa,0],gx_data[fa,1],gx_data[fa,2],gx_data[fa,3],gx_data[fa,4],gx_data[fa,5],gx_data[fa,6],gx_data[fa,7],gx_data[fa,8],gx_data[fa,9],gx_data[fa,10],gx_data[0,11],gx_data[fa,12],gx_data[fa,13],gx_data[fa,14],gx_data[fa,15],gx_data[fa,16],gx_data[fa,17],gx_data[fa,18],gx_data[fa,19],gx_data[fa,20],gx_data[fa,21],gx_data[fa,22],gx_data[fa,23],gx_data[fa,24],gx_data[fa,25],gx_data[fa,26],gx_data[fa,27],gx_data[fa,28],gx_data[fa,29],gx_data[fa,30],gx_data[fa,31],gx_data[fa,32],gx_data[fa,33],gx_data[fa,34],gx_data[fa,35],gx_data[fa,36],gx_data[fa,37],gx_data[fa,38],gx_data[fa,39],gx_data[fa,40],gy_data[fa,0]))\n",
    "                \n",
    "            #print(\"[{}] Prediction: {} Real Y: {}\".format(p == int(y), p, int(y)))\n",
    "    f.close()\n",
    "    print(\"true={} false: {} acc: {:0.2f}\".format(tr,fa,tr/(tr+fa)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "ename": "FailedPreconditionError",
     "evalue": "Attempting to use uninitialized value bias3_43\n\t [[Node: bias3_43/read = Identity[T=DT_FLOAT, _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](bias3_43)]]\n\nCaused by op 'bias3_43/read', defined at:\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\runpy.py\", line 193, in _run_module_as_main\n    \"__main__\", mod_spec)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel_launcher.py\", line 16, in <module>\n    app.launch_new_instance()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\traitlets\\config\\application.py\", line 658, in launch_instance\n    app.start()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\kernelapp.py\", line 486, in start\n    self.io_loop.start()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 127, in start\n    self.asyncio_loop.run_forever()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\asyncio\\base_events.py\", line 421, in run_forever\n    self._run_once()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\asyncio\\base_events.py\", line 1425, in _run_once\n    handle._run()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\asyncio\\events.py\", line 127, in _run\n    self._callback(*self._args)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 117, in _handle_events\n    handler_func(fileobj, events)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tornado\\stack_context.py\", line 276, in null_wrapper\n    return fn(*args, **kwargs)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py\", line 450, in _handle_events\n    self._handle_recv()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py\", line 480, in _handle_recv\n    self._run_callback(callback, msg)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py\", line 432, in _run_callback\n    callback(*args, **kwargs)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tornado\\stack_context.py\", line 276, in null_wrapper\n    return fn(*args, **kwargs)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 283, in dispatcher\n    return self.dispatch_shell(stream, msg)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 233, in dispatch_shell\n    handler(stream, idents, msg)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 399, in execute_request\n    user_expressions, allow_stdin)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\ipkernel.py\", line 208, in do_execute\n    res = shell.run_cell(code, store_history=store_history, silent=silent)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\zmqshell.py\", line 537, in run_cell\n    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2662, in run_cell\n    raw_cell, store_history, silent, shell_futures)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2785, in _run_cell\n    interactivity=interactivity, compiler=compiler, result=result)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2903, in run_ast_nodes\n    if self.run_code(code, result):\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2963, in run_code\n    exec(code_obj, self.user_global_ns, self.user_ns)\n  File \"<ipython-input-98-14fb84576533>\", line 19, in <module>\n    b3=tf.Variable(tf.random_normal([nb_classes]),name='bias3')\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\ops\\variables.py\", line 259, in __init__\n    constraint=constraint)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\ops\\variables.py\", line 422, in _init_from_args\n    self._snapshot = array_ops.identity(self._variable, name=\"read\")\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\ops\\array_ops.py\", line 79, in identity\n    return gen_array_ops.identity(input, name=name)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\ops\\gen_array_ops.py\", line 3887, in identity\n    \"Identity\", input=input, name=name)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\framework\\op_def_library.py\", line 787, in _apply_op_helper\n    op_def=op_def)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\", line 3414, in create_op\n    op_def=op_def)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\", line 1740, in __init__\n    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access\n\nFailedPreconditionError (see above for traceback): Attempting to use uninitialized value bias3_43\n\t [[Node: bias3_43/read = Identity[T=DT_FLOAT, _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](bias3_43)]]\n",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mFailedPreconditionError\u001b[0m                   Traceback (most recent call last)",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_call\u001b[1;34m(self, fn, *args)\u001b[0m\n\u001b[0;32m   1321\u001b[0m     \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1322\u001b[1;33m       \u001b[1;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1323\u001b[0m     \u001b[1;32mexcept\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mOpError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_run_fn\u001b[1;34m(feed_dict, fetch_list, target_list, options, run_metadata)\u001b[0m\n\u001b[0;32m   1306\u001b[0m       return self._call_tf_sessionrun(\n\u001b[1;32m-> 1307\u001b[1;33m           options, feed_dict, fetch_list, target_list, run_metadata)\n\u001b[0m\u001b[0;32m   1308\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_call_tf_sessionrun\u001b[1;34m(self, options, feed_dict, fetch_list, target_list, run_metadata)\u001b[0m\n\u001b[0;32m   1408\u001b[0m           \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_session\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moptions\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetch_list\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtarget_list\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1409\u001b[1;33m           run_metadata)\n\u001b[0m\u001b[0;32m   1410\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mFailedPreconditionError\u001b[0m: Attempting to use uninitialized value bias3_43\n\t [[Node: bias3_43/read = Identity[T=DT_FLOAT, _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](bias3_43)]]",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mFailedPreconditionError\u001b[0m                   Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-101-f695e1819eb9>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSession\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0msess\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m     \u001b[0mpred\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msess\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprediction\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mx_data\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m     \u001b[1;32mfor\u001b[0m \u001b[0mp\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpred\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my_data\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mflatten\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m             \u001b[1;32mif\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mp\u001b[0m\u001b[1;33m==\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m                 \u001b[0mtr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtr\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36mrun\u001b[1;34m(self, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m    898\u001b[0m     \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    899\u001b[0m       result = self._run(None, fetches, feed_dict, options_ptr,\n\u001b[1;32m--> 900\u001b[1;33m                          run_metadata_ptr)\n\u001b[0m\u001b[0;32m    901\u001b[0m       \u001b[1;32mif\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    902\u001b[0m         \u001b[0mproto_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrun_metadata_ptr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_run\u001b[1;34m(self, handle, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m   1133\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mfinal_fetches\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mfinal_targets\u001b[0m \u001b[1;32mor\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mhandle\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mfeed_dict_tensor\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1134\u001b[0m       results = self._do_run(handle, final_targets, final_fetches,\n\u001b[1;32m-> 1135\u001b[1;33m                              feed_dict_tensor, options, run_metadata)\n\u001b[0m\u001b[0;32m   1136\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1137\u001b[0m       \u001b[0mresults\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_run\u001b[1;34m(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m   1314\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mhandle\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1315\u001b[0m       return self._do_call(_run_fn, feeds, fetches, targets, options,\n\u001b[1;32m-> 1316\u001b[1;33m                            run_metadata)\n\u001b[0m\u001b[0;32m   1317\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1318\u001b[0m       \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_do_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_prun_fn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhandle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeeds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetches\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_call\u001b[1;34m(self, fn, *args)\u001b[0m\n\u001b[0;32m   1333\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1334\u001b[0m           \u001b[1;32mpass\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1335\u001b[1;33m       \u001b[1;32mraise\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnode_def\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmessage\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1336\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1337\u001b[0m   \u001b[1;32mdef\u001b[0m \u001b[0m_extend_graph\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mFailedPreconditionError\u001b[0m: Attempting to use uninitialized value bias3_43\n\t [[Node: bias3_43/read = Identity[T=DT_FLOAT, _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](bias3_43)]]\n\nCaused by op 'bias3_43/read', defined at:\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\runpy.py\", line 193, in _run_module_as_main\n    \"__main__\", mod_spec)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel_launcher.py\", line 16, in <module>\n    app.launch_new_instance()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\traitlets\\config\\application.py\", line 658, in launch_instance\n    app.start()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\kernelapp.py\", line 486, in start\n    self.io_loop.start()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 127, in start\n    self.asyncio_loop.run_forever()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\asyncio\\base_events.py\", line 421, in run_forever\n    self._run_once()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\asyncio\\base_events.py\", line 1425, in _run_once\n    handle._run()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\asyncio\\events.py\", line 127, in _run\n    self._callback(*self._args)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 117, in _handle_events\n    handler_func(fileobj, events)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tornado\\stack_context.py\", line 276, in null_wrapper\n    return fn(*args, **kwargs)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py\", line 450, in _handle_events\n    self._handle_recv()\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py\", line 480, in _handle_recv\n    self._run_callback(callback, msg)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py\", line 432, in _run_callback\n    callback(*args, **kwargs)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tornado\\stack_context.py\", line 276, in null_wrapper\n    return fn(*args, **kwargs)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 283, in dispatcher\n    return self.dispatch_shell(stream, msg)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 233, in dispatch_shell\n    handler(stream, idents, msg)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\kernelbase.py\", line 399, in execute_request\n    user_expressions, allow_stdin)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\ipkernel.py\", line 208, in do_execute\n    res = shell.run_cell(code, store_history=store_history, silent=silent)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\ipykernel\\zmqshell.py\", line 537, in run_cell\n    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2662, in run_cell\n    raw_cell, store_history, silent, shell_futures)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2785, in _run_cell\n    interactivity=interactivity, compiler=compiler, result=result)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2903, in run_ast_nodes\n    if self.run_code(code, result):\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 2963, in run_code\n    exec(code_obj, self.user_global_ns, self.user_ns)\n  File \"<ipython-input-98-14fb84576533>\", line 19, in <module>\n    b3=tf.Variable(tf.random_normal([nb_classes]),name='bias3')\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\ops\\variables.py\", line 259, in __init__\n    constraint=constraint)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\ops\\variables.py\", line 422, in _init_from_args\n    self._snapshot = array_ops.identity(self._variable, name=\"read\")\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\ops\\array_ops.py\", line 79, in identity\n    return gen_array_ops.identity(input, name=name)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\ops\\gen_array_ops.py\", line 3887, in identity\n    \"Identity\", input=input, name=name)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\framework\\op_def_library.py\", line 787, in _apply_op_helper\n    op_def=op_def)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\", line 3414, in create_op\n    op_def=op_def)\n  File \"C:\\Users\\SANHA\\Anaconda3\\envs\\py35\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\", line 1740, in __init__\n    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access\n\nFailedPreconditionError (see above for traceback): Attempting to use uninitialized value bias3_43\n\t [[Node: bias3_43/read = Identity[T=DT_FLOAT, _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](bias3_43)]]\n"
     ]
    }
   ],
   "source": [
    "with tf.Session() as sess:  \n",
    "    pred = sess.run(prediction, feed_dict={X: x_data})\n",
    "    for p, y in zip(pred, y_data.flatten()):\n",
    "            if(p==int(y)):\n",
    "                tr=tr+1\n",
    "            else:\n",
    "                fa=fa+1\n",
    "                #print(gx_data)\n",
    "                f.write(\"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \\n\" %(gx_data[fa,0],gx_data[fa,1],gx_data[fa,2],gx_data[fa,3],gx_data[fa,4],gx_data[fa,5],gx_data[fa,6],gx_data[fa,7],gx_data[fa,8],gx_data[fa,9],gx_data[fa,10],gx_data[0,11],gx_data[fa,12],gx_data[fa,13],gx_data[fa,14],gx_data[fa,15],gx_data[fa,16],gx_data[fa,17],gx_data[fa,18],gx_data[fa,19],gx_data[fa,20],gx_data[fa,21],gx_data[fa,22],gx_data[fa,23],gx_data[fa,24],gx_data[fa,25],gx_data[fa,26],gx_data[fa,27],gx_data[fa,28],gx_data[fa,29],gx_data[fa,30],gx_data[fa,31],gx_data[fa,32],gx_data[fa,33],gx_data[fa,34],gx_data[fa,35],gx_data[fa,36],gx_data[fa,37],gx_data[fa,38],gx_data[fa,39],gx_data[fa,40],gy_data[fa,0]))\n",
    "                \n",
    "            #print(\"[{}] Prediction: {} Real Y: {}\".format(p == int(y), p, int(y)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
